package ai.othello.graphic;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class OthelloActivity extends Activity {

	private int algorithm;
	private int vs;
	private int level;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button bntPlay = (Button)findViewById(R.id.bntPlay);
		bntPlay.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				AlertDialog.Builder b = new AlertDialog.Builder(OthelloActivity.this);
				b.setTitle("Choice of algorithm");
				b.setSingleChoiceItems(new String[]{
						getString(R.string.minmaxText),
						getString(R.string.alphabetaText)
				}, -1, new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						algorithm = which;
					}
				});
				b.setPositiveButton("Next", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

						AlertDialog.Builder lev = new AlertDialog.Builder(OthelloActivity.this);
						lev.setTitle("Level");
						lev.setSingleChoiceItems(new String[]{
								getString(R.string.uno),
								getString(R.string.due),
								getString(R.string.tre),
								getString(R.string.quattro),
								getString(R.string.cinque),
								getString(R.string.sei),
								getString(R.string.sette),
								getString(R.string.otto),
								getString(R.string.nove),
								getString(R.string.dieci),
						}, -1, new OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								level = which;
							}
						}
								);
						lev.setPositiveButton("Next", new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {

								AlertDialog.Builder avv = new AlertDialog.Builder(OthelloActivity.this);
								avv.setTitle("Game mode");
								avv.setSingleChoiceItems(new String[]{
										getString(R.string.device_device),
										getString(R.string.player_device)
								}, -1, new OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog, int which) {
										vs = which;
									}
								});
								avv.setPositiveButton("Play", new DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog, int which) {
										Intent play = new Intent(OthelloActivity.this, PlayActivity.class);
										play.putExtra("vs", vs);
										play.putExtra("algorithm", algorithm);
										play.putExtra("level", level);
										startActivity(play);
										dialog.dismiss();
										finish();
									}
								});
								avv.setNegativeButton("Cancel", null);
								avv.show();
							}

						});
						lev.setNegativeButton("Cancel", null);
						lev.show();
					}
				});
				b.setNegativeButton(R.string.cancel, null);
				b.show();
			}
		});        

		Button bntInst = (Button)findViewById(R.id.bntInstruction);
		bntInst.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent inst = new Intent(OthelloActivity.this, InstructionActivity.class);
				startActivity(inst);
			}
		}); 

		Button bntExit = (Button)findViewById(R.id.bntExit);
		bntExit.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				finish();
			}
		});
	}
}
